<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>上海泛软科技有限公司-后台登陆</title>
<meta name="robots" content="nofollow" />
<meta name=”viewport” content=”width=device-width, initial-scale=1, maximum-scale=1″>
<link href="/Public/Css/admin-style.css" rel="stylesheet" type="text/css" />
<link href="/Public/Css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="/Public/Css/bootstrap.min.css" rel="stylesheet" type="text/css" />


<script language="javascript" type="text/javascript" src="/Public/Js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/admin-common.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/bootstrap.min.js"></script>
<!--<script language="javascript" type="text/javascript" src="/Public/Js/bootstrap.js"></script> -->
<script language="javascript" type="text/javascript" src="/Public/Js/rock_customer_list.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/demo.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/blob.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/FileSaver.min.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/jquery.base64.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/jquery-1.10.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/tableExport.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/xlsx.core.min.js"></script>
</head>

<body>

 <h4>设备增加</h4>
  <form class="form-horizontal" role="form" style="width:100%;" enctype="multipart/form-data" name="form1" method="post" action="<?php echo U('add_device');?>">
   <div style="width:80%; border: 1px solid #ccc;padding:10px;margin-bottom:30px;margin-left:10%"> 
	<div style="width:60%;margin-left:15%">  	 
	 <h4>设备信息:</h4>
	 <div class="form-group">
		<label for="firstname" class="col-sm-2 control-label">设备编号</label>
		<div class="col-sm-10">
		  <input required="required" type="text" class="form-control" name="device_no" id="device_no" placeholder="请输入设备编号">
		</div>
	  </div>
	  <div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">设备标识</label>
		<div class="col-sm-10">
		  <input required="required" type="text" name="device_name" class="form-control" id="device_name" placeholder="请输入设备标识">
		</div>
	  </div>
	  <div class="form-group">
		<label for="firstname" class="col-sm-2 control-label">设备类型</label>
		<div class="col-sm-10">
		  <select style="width:100%" name="device_style" id="device_style">
			<option>体温计</option>
		  </select>	
		</div>
	  </div>
	  <div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">设备状态</label>
		<div class="col-sm-10">
		  <select style="width:100%" name="device_status" id="device_status">
			<option>未连接</option>
			<option>已连接</option>
			<option>设备故障</option>
		  </select>	
		</div>
	  </div>
	 </div>
    </div>	
    <div style="width:80%; border: 1px solid #ccc;padding:10px;margin-bottom:30px;margin-left:10%"> 
	<div style="width:60%;margin-left:15%">  	 
	 <h4>医院信息:</h4>
	 <div class="form-group old_hos">
		<label for="" class="col-sm-2 control-label">医院</label>
		<div class="col-sm-10">
		  <select style="width:100%" name="hospital_name" id="hospital_name" onchange="choose_hos()">
			<?php if(is_array($hospital_name)): $i = 0; $__LIST__ = $hospital_name;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$hospital_name): $mod = ($i % 2 );++$i;?><option h_id="<?php echo ($hospital_name['h_id']); ?>"><?php echo ($hospital_name["h_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
		  </select>	
		</div>
	  </div>
	   <input style="display:none" type="text" class="form-control" name="hosid" id="hosid" placeholder="">
		 
	  <a id="add_new_hos" onclick="add_new_hos()">增加新的医院</a>
	  <div class="form-group new_add">
		<label for="" class="col-sm-2 control-label">医院名称:</label>
		<div class="col-sm-10">
		  <input  type="text" class="form-control" name="hos_name" id="hos_name" placeholder="请输入医院名称">
		</div>
	  </div>
	  
	  <div class="form-group new_add">
		<label for="" class="col-sm-2 control-label">省份:</label>
		<div class="col-sm-10">
		  <input  type="text" class="form-control" name="province" id="province" placeholder="请输入城市">
		</div>
	  </div>
	  <div class="form-group new_add">
		<label for="" class="col-sm-2 control-label">城市、区、县</label>
		<div class="col-sm-10">
		  <input  type="text" class="form-control" name="city" id="city" placeholder="请输入区、县">
		</div>
	  </div>
	  <div class="form-group new_add">
		<label for="" class="col-sm-2 control-label">经纬度</label>
		<div class="col-sm-10">
		  <input  style="width:40%;float:left;margin-right:5%" type="text" class="form-control" name="lng" id="lng" placeholder="请输入经度">
		  <input  style="width:40%;float:left;margin-right:2%" type="text" class="form-control" name="lat" id="lat" placeholder="请输入纬度">
		  <button type="button" class="btn btn-primary btn-sm" onclick="obtain()">获取</button>
		 
		</div>
	  </div>
	 </div>
    </div>	
 
    <div style="width:80%; border: 1px solid #ccc;padding:10px;margin-bottom:30px;margin-left:10%"> 
	<div style="width:60%;margin-left:15%">  	 
	 <h4>用户信息:</h4>
	  <div class="form-group user_old" >
		<label for="" class="col-sm-2 control-label">手机号:</label>
		<div class="col-sm-10">
		  <select  style="width:100%" name="user_tel" id="user_tel" onchange="choose_user()">
			<option></option>
		  </select>	
		</div>
	  </div>
	   <div class="form-group user_old">
		<label for="" class="col-sm-2 control-label">姓名:</label>
		<div class="col-sm-10">
		  <input readonly="readonly" type="text" class="form-control" name="user_name" id="user_name" placeholder="请输入用户姓名">
		</div>
	  </div>
	   <input  type="text" style="display:none" class="form-control" name="user_id" id="user_id" placeholder="">
	  <a id="add_new_user" onclick="add_new_user()">增加新的用户</a>
	    <div class="form-group user_new">
		 <label for="" class="col-sm-2 control-label">姓名:</label>
		 <div class="col-sm-10">
		  <input  type="text" class="form-control" name="new_user_name" id="new_user_name" placeholder="请输入用户姓名">
		</div>
	   </div>
	   <div class="form-group user_new">
		 <label for="" class="col-sm-2 control-label">密码:</label>
		 <div class="col-sm-10">
		  <input  type="password" class="form-control" name="new_user_password" id="new_user_password" placeholder="请输入用密码">
		</div>
	   </div>
	    <div class="form-group user_new">
		 <label for="" class="col-sm-2 control-label">手机号:</label>
		 <div class="col-sm-10">
		  <input  type="text" class="form-control" name="new_user_Tel" id="new_user_Tel" placeholder="请输入手机号">
		</div>
	   </div>
	   <div class="form-group user_new">
		 <label for="" class="col-sm-2 control-label">职位:</label>
		 <div class="col-sm-10">
		  <input  type="text" class="form-control" name="new_user_postion" id="new_user_postion" placeholder="请输入职位">
		</div>
	   </div>
	   <div class="form-group user_new">
		 <label for="" class="col-sm-2 control-label">工作区域:</label>
		 <div class="col-sm-10">
		  <input  type="text" class="form-control" name="new_user_work" id="new_user_work" placeholder="请输入工作区域">
		</div>
	   </div>
	 </div>
    </div>	
     
	<div class="form-group" style="text-align:right;margin-right:10%">
       <div class="col-sm-offset-2 col-sm-10">
         <button type="submit" class="btn btn-info sub_data">提交</button>
       </div>
    </div>

 </form>
 <script>
  var flag = 0;
  $(".new_add").css("display","none");
  function add_new_hos(){
   if($("#add_new_hos").html() == "增加新的医院"){
     $(".old_hos").css("display","none");
	 $(".new_add").css("display","block");
	 $("#add_new_hos").html("选择现有医院");
	 $(".user_old").css("display","none");
	 //$("#add_new_user").css("display","none");
	// add_new_user();
	 flag = 1;
   }else{
     $(".old_hos").css("display","block");
	 $(".new_add").css("display","none");
	 $("#add_new_hos").html("增加新的医院");
	 //$(".user_old").attr("display","block");
	  $(".user_old").css("display","block");
	 flag = 0;
   }
   if(flag == 1){
    $("#hosid").val('');
    $(".new_add").children().next().children().attr("required","required");
    }else{
	  $("#hosid").val($("#hospital_name option:first").attr("h_id"));
	  $("#hospital_name option:first").prop("selected", 'selected');
	  $(".new_add").children().next().children().attr("required",false);
	}
  }
  function obtain(){//获取经纬度
     var hos_name1 = $("#hos_name").val();
	 $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/from_Name_GetData',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   hos_name:hos_name1
		 },
 	     success: function(data){
		  debugger;
          if(data["lng"] && data["lat"]){
		     $("#lng").val(data["lng"]);
		     $("#lat").val(data["lat"]);
		  }else{
		    alert(data);
			$("#lng").val('');
		    $("#lat").val('');
		  }		 
		  
		 }
	   });
  }
  choose_hos();
  $("#hospital_name option:first").prop("selected", 'selected');
  $("#hosid").val($("#hospital_name option:first").attr("h_id"));
  function choose_hos(){
    var options=$("#hospital_name option:selected").attr("h_id");  //获取选中的项
	$("#hosid").val(options);
	if(flag == 0){
	   $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/add_device_user',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   h_id:$("#hosid").val()
		 },
 	     success: function(data){
		    if(data.length == 0){
			  $("#user_name").val("没有用户");
			  $("#user_tel").val("");
			  $("#user_tel").attr("disabled","disabled");
			  $("#user_id").val('');
			  return;
			}
			$("#user_tel").attr("disabled",false);
		    var html='';
			for(var i=0; i < data.length; i++){
			   html+=
			   '<option>'+data[i]["u_phonenum"]+'</option>'
			}
		   $("#user_tel").html(html);
		   for(var i = 0 ; i < data.length; i++){
		     if($("#user_tel").val()== data[i]["u_phonenum"]){
			    $("#user_name").val(data[i]["u_realname"]);
				$("#user_id").val(data[i]["u_id"]);
			 }
		   }
	      $("#user_tel").click(function(){
		     for(var i = 0 ; i < data.length; i++){
		     if($("#user_tel").val()== data[i]["u_phonenum"]){
			    $("#user_name").val(data[i]["u_realname"]);
				$("#user_id").val(data[i]["u_id"]);
			 }
			 
		   }
		  })
		 }
	   });
	}
  }
  //增加新的用户
  var flag1 = 0;
  $(".user_new").css("display","none");
  function add_new_user(){
    if( $("#add_new_user").html()== "增加新的用户"){
	   $(".user_old").css("display","none");
	   $(".user_new").css("display","block");
	   $("#add_new_user").html("选择现有用户");
	   flag1 = 1;
	   
	}else{
	  $(".user_old").css("display","block");
	  $(".user_new").css("display","none");
	  $("#add_new_user").html("增加新的用户");
	  if($("#add_new_hos").html() == "选择现有医院"){
	      $(".user_old").css("display","none");
	   }
	  flag1 = 0;
	}
     if(flag1 == 1){
	   $("#user_id").val('');
	   $(".user_new").children().next().children().attr("required","required");
	 }else{
	   $("#user_tel").click();
	   $(".user_new").children().next().children().attr("required",false);
	 }
  }
  
 </script>

</body>
</html>